package com.hyp.pay.UI.Home.presenter;

import android.util.Log;

import com.hyp.pay.UI.Home.presenter.contract.Edit2Contract;
import com.hyp.pay.UI.Home.presenter.contract.EditContract;
import com.hyp.pay.base.RxPresenter;
import com.hyp.pay.http.Constants;
import com.hyp.pay.http.RetrofitHelper;
import com.hyp.pay.model.FindRecharge;
import com.hyp.pay.model.UserJson;

import org.json.JSONException;

import java.io.File;

import javax.inject.Inject;

import io.reactivex.Flowable;
import io.reactivex.subscribers.ResourceSubscriber;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;

/**
 * Created by Administrator on 2017/6/2.
 */

public class Edit2Presenter extends RxPresenter<Edit2Contract.View> implements Edit2Contract.Presenter{

    private RetrofitHelper mRetrofitHelper;

    @Inject
    public Edit2Presenter(RetrofitHelper mRetrofitHelper) {
        this.mRetrofitHelper = mRetrofitHelper;
    }



    @Override
    public void getFindRecharge(String charge) {
        Flowable<FindRecharge> flowable = mRetrofitHelper.findRecharge(charge);
        ResourceSubscriber subscriber = mRetrofitHelper.startObservable(flowable, new ResourceSubscriber<FindRecharge>() {

            @Override
            public void onNext(FindRecharge data) {

                Log.i("olj",data.toString());

                if (getView() != null) {
                    getView().showFindRecharge(data);
                }

            }

            @Override
            public void onError(Throwable t) {
                t.printStackTrace();
                if (getView() != null)
                    getView().showError(Constants.GRS_ERROR);
            }

            @Override
            public void onComplete() {

            }
        });

        addSubscription(subscriber);
    }

}
